var amapFile = require('../../../../libs/amap-wx.130');
const requests = require("../../../../utils/request")

const app = getApp()
const request = require('../../../../utils/request')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    user:'',
    address:'',
    phoneNum:'',
  },


  async updateAddress()
  {
    const {address,user,phoneNum} = this.data
    let res = await requests.addressInterface(address,null,user,phoneNum,app.globalData.openid,null,'saveOrUpdate')
    // console.log('修改的地址',res.data.data.value)

    wx.navigateBack({
      delta: 0,
    })
  },
  getAddressInfo()
  {
    var that = this;
    var myAmapFun = new amapFile.AMapWX({key:'4f2354b3309e2b695928d67e2ad965be'});
    myAmapFun.getRegeo({
      success: function(data){
        console.log(data[0])
        that.setData({
          address:data[0].regeocodeData.formatted_address
        })
      },
      fail: function(info){
        //失败回调
        console.log(info)
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad:async function (opt) {
    // console.log(opt)
    // console.log(opt.addressId)
    let res = await request.addressInterface(null,opt.addressid,null,null,null,null,'getById')
    // console.log(res.data.data.value)
    const {name,telphone,address} = res.data.data.value
    this.setData({
      user:name,
      address:address,
      phoneNum:telphone
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})